home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
- Subject: Re: How can I check whether I file exists in a multi-user environment?
- Date: 1 Apr 1996 19:37:39 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jq0d3$9pd@solutions.solon.com>
- References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net> <4jjn1d$clu@solutions.solon.com> <Dp6sqL.Buz@iquest.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <Dp6sqL.Buz@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
- >seebs@solutions.solon.com (Peter Seebach) wrote:
- >>The reason this is a poor solution is that it doesn't test for existance,
- >>it tests for accessibility.
-
- >You should check your facts more carefully. You evidently are unfamiliar
- >with the behavior of access( ). It is defined thusly:
-
- It isn't defined at all, except by various external standards.
-
- POSIX defines it one way.
-
- >#include <io.h>
-
- As noted, this is incorrect for the only actual *standard* that specifies
- access. It's <unistd.h>
-
- >permissible values for amode are:
- > 06 check for read and write permission
- > 04 check for read permission
- > 02 check for write permission
- > 01 execute
- >>>>> 00 check for existence of file <<<<<
-
- This is all incorrect. The modes are R_OK, X_OK, W_OK, and F_OK, and may
- be ored. Quoting specific numbers from a specific implementation is
- unuseful.
-
- >Return value: If the requested access is allowed, access() returns 0;
- >otherwise it returns a value
- >of -1, and the global variable errno is set to one of the following:
- > ENOENT Path or file name not found
- > EACCES Permission denied
-
- >As I coded it, this is a test for the existence of the file, not its
- >accessibility.
-
- You missed the point completely, dimwit. Create a file. Now mark the
- directory it's in unreadable, unwriteable, unexecutable, etc etc.
-
- Now try your test. And gee, you'll get EACCES, most likely. Because,
- if you don't have the permissions needed to look in the directory,
- it's *IMPOSSIBLE* to test for existance.
-
- As I said, this tests for accessability.
-
- Feel free to email me a sample program, using POSIX standard code, and I'll
- gladly test it. :)
-
- (But this really should leave the newsgroup now.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-